package com.sc.nft.dao;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.sc.nft.entity.vo.ecology.AdminDaoEcologyIncomePageVO;
import com.sc.nft.enums.EcologyHatchDaoIncomeDimensionalityEnum;
import com.sc.nft.enums.EcologyIncomeTypeEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.EcologyHatchDaoIncomeConf;
import com.sc.nft.mapper.EcologyHatchDaoIncomeConfMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * 生态-DAO收益配置(sc_ecology_hatch_dao_income_conf)数据DAO
 *
 * @author Sun
 * @since 2023-12-02 16:37:21
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class EcologyHatchDaoIncomeConfDao extends ServiceImpl<EcologyHatchDaoIncomeConfMapper, EcologyHatchDaoIncomeConf> {

    public Page<AdminDaoEcologyIncomePageVO> getPage(String daoName, String dividendIncomeName, Boolean status, Integer pageNo, Integer pageSize) {
        return baseMapper.getPage(new Page<>(pageNo, pageSize),daoName, dividendIncomeName, status);
    }

    public Boolean getExistIncomeByDaoIdAndCollectionIdAndIncomeTypeAndDimensionality(Long daoId,EcologyIncomeTypeEnum daoIncomeType, EcologyHatchDaoIncomeDimensionalityEnum dimensionality,Long collectionId) {
        LambdaQueryWrapper<EcologyHatchDaoIncomeConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyHatchDaoIncomeConf::getDaoId,daoId);
        wrapper.eq(EcologyHatchDaoIncomeConf::getDaoIncomeType,daoIncomeType);
        wrapper.eq(ObjectUtil.isNotNull(dimensionality),EcologyHatchDaoIncomeConf::getDimensionality,dimensionality);
        wrapper.eq(EcologyHatchDaoIncomeConf::getCollectionId,collectionId);
        List<EcologyHatchDaoIncomeConf> list = list(wrapper);
        return list.size() == 0;
    }

    public Boolean getExistIncomeByDaoIdAndHatchCollectionId(Long daoId,Long hatchCollectionId,EcologyIncomeTypeEnum daoIncomeType) {
        LambdaQueryWrapper<EcologyHatchDaoIncomeConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyHatchDaoIncomeConf::getDaoId,daoId);
        wrapper.eq(EcologyHatchDaoIncomeConf::getHatchCollectionId,hatchCollectionId);
        wrapper.eq(EcologyHatchDaoIncomeConf::getDaoIncomeType,daoIncomeType);
        Integer selectCount = baseMapper.selectCount(wrapper);
        return SqlHelper.retBool(selectCount);
    }

    public Boolean getExistIncomeByDaoIdAndHatchCollectionIdNotId(Long id,Long daoId,Long hatchCollectionId,EcologyIncomeTypeEnum daoIncomeType) {
        LambdaQueryWrapper<EcologyHatchDaoIncomeConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.ne(ObjectUtil.isNotNull(id),EcologyHatchDaoIncomeConf::getId,id);
        wrapper.eq(EcologyHatchDaoIncomeConf::getDaoId,daoId);
        wrapper.eq(EcologyHatchDaoIncomeConf::getHatchCollectionId,hatchCollectionId);
        wrapper.eq(EcologyHatchDaoIncomeConf::getDaoIncomeType,daoIncomeType);
        Integer selectCount = baseMapper.selectCount(wrapper);
        return SqlHelper.retBool(selectCount);
    }


    public BigDecimal getSumIncomeScaleByDaoIdAndDaoIdentityId(Long daoId, Long hatchCollectionId) {
        return baseMapper.getSumIncomeScaleByDaoIdAndDaoIdentityId(daoId,hatchCollectionId);
    }

    public Boolean updateConfById(EcologyHatchDaoIncomeConf updateData) {
        LambdaUpdateWrapper<EcologyHatchDaoIncomeConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyHatchDaoIncomeConf::getId,updateData.getId());
        wrapper.set(EcologyHatchDaoIncomeConf::getIncomeScale,updateData.getIncomeScale());
        wrapper.set(EcologyHatchDaoIncomeConf::getDaoIdentityId,updateData.getDaoIdentityId());
        wrapper.set(EcologyHatchDaoIncomeConf::getDirectThrustUserCount,updateData.getDirectThrustUserCount());
        wrapper.set(EcologyHatchDaoIncomeConf::getDimensionality,updateData.getDimensionality());
        wrapper.set(EcologyHatchDaoIncomeConf::getDaoIncomeType,updateData.getDaoIncomeType());
        wrapper.set(EcologyHatchDaoIncomeConf::getDividendIncomeName,updateData.getDividendIncomeName());
        wrapper.set(EcologyHatchDaoIncomeConf::getHoldCollectionId,updateData.getHoldCollectionId());
        wrapper.set(EcologyHatchDaoIncomeConf::getHoldCollectionName,updateData.getHoldCollectionName());
        wrapper.set(EcologyHatchDaoIncomeConf::getHatchCollectionId,updateData.getHatchCollectionId());
        wrapper.set(EcologyHatchDaoIncomeConf::getCollectionId,updateData.getCollectionId());
        return update(wrapper);
    }

    public List<EcologyHatchDaoIncomeConf> getListByStatusAndType(EcologyIncomeTypeEnum daoIncomeType, Boolean status) {
        LambdaQueryWrapper<EcologyHatchDaoIncomeConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyHatchDaoIncomeConf::getDaoIncomeType,daoIncomeType);
        wrapper.eq(EcologyHatchDaoIncomeConf::getStatus,status);
        return list(wrapper);
    }

    public boolean updateStatusById(Long id, Boolean status) {
        LambdaUpdateWrapper<EcologyHatchDaoIncomeConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyHatchDaoIncomeConf::getId,id);
        wrapper.set(EcologyHatchDaoIncomeConf::getStatus,status);
        return update(wrapper);
    }

    public Boolean deleteConf(Long id) {
        LambdaUpdateWrapper<EcologyHatchDaoIncomeConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyHatchDaoIncomeConf::getId,id);
        return remove(wrapper);
    }

    public List<EcologyHatchDaoIncomeConf> getListByDaoId(Long daoId,Long hatchCollectionId) {
        LambdaUpdateWrapper<EcologyHatchDaoIncomeConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyHatchDaoIncomeConf::getDaoId,daoId);
        wrapper.eq(EcologyHatchDaoIncomeConf::getHatchCollectionId,hatchCollectionId);

        return list(wrapper);
    }


    public Boolean updateIncomeScaleBalanceByAndId(Long id,BigDecimal incomeScaleBalance) {
        LambdaUpdateWrapper<EcologyHatchDaoIncomeConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyHatchDaoIncomeConf::getId,id);
        wrapper.set(EcologyHatchDaoIncomeConf::getIncomeScaleBalance,incomeScaleBalance);
        return update(wrapper);
    }


}